package com.ruoyi.web.controller.note;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.note.domain.TBook;
import com.ruoyi.note.service.*;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 笔记管理Controller
 *
 * @author cl
 * @date 2021-04-15
 */
@RestController
@RequestMapping("/note/index")
public class IndexController extends BaseController {
    @Autowired
    private ITBookService tBookService;
    @Autowired
    private ITBookContentService itBookContentService;
    @Autowired
    private ITBookChapterService itBookChapterService;
    @Autowired
    private ITQuestionService questionService;
    @Autowired
    private ITBookKeyService bookKeyService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询笔记管理列表
     */
    @PreAuthorize("@ss.hasPermi('note:index:count')")
    @GetMapping("/count")
    public AjaxResult count(HttpServletRequest request) {
        Map result = new HashMap();
        Long userId = tokenService.getLoginUser(request).getUser().getUserId();
        result.put("bookNums", tBookService.countAll(userId));
        result.put("contentNums", itBookContentService.countAll(userId));
        result.put("questionNums", questionService.countAll(userId));
        result.put("chapterNums", itBookChapterService.countAll(userId));
        result.put("wordNums", bookKeyService.countAll(userId));
        return AjaxResult.success(result);
    }

    @PreAuthorize("@ss.hasPermi('note:index:addTrend')")
    @GetMapping("/addTrend")
    public AjaxResult addTrend(HttpServletRequest request) {
        Map result = new HashMap();
        Long userId = tokenService.getLoginUser(request).getUser().getUserId();
        result.put("contentAddTrend", itBookContentService.addTrend(userId));
        result.put("questionAddTrend", questionService.addTrend(userId));
        result.put("wordAddTrend", bookKeyService.addTrend(userId));
        return AjaxResult.success(result);
    }
}
